package com.rd.student.jike.class2.lihongming.Solutions5;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @Auther:Heinrich
 * @Date:2023/7/31-07-31-14:48
 * @Description:c230731
 * @version:1.0
 */
//"E:\\代码\\DataStructures/A.txt"
//".\\src\\com\\rd\\student\\jike\\class2\\lihongming\\Solutions5/A.txt"
//String str = "E:\\rd2304\\src\\com\\rd\\student\\jike\\class2\\lihongming\\Solutions5\\A.txt";
public class Question4 {

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        String str1 =scanner.nextLine();
        //System.out.println(str1);
        String str = reader(str1);
        for (int i = 0; i < str.length() ; i++) {
            if(str.charAt(i)<65||(str.charAt(i)>90&&str.charAt(i)<97)||str.charAt(i)>122){
                str = str.replace(str.charAt(i),' ');
            }
        }
        String[] words = str.split(" ");
        //System.out.println(Arrays.toString(words));
        HashMap wordStats = new HashMap();
        for (int i = 0; i < words.length; i++) {
            if(!wordStats.containsKey(words[i])){
                wordStats.put(words[i],1);
            }else{
                wordStats.replace(words[i],(int)(wordStats.get(words[i]))+1);
            }
        }
        wordStats.remove("");
        //System.out.println(wordStats);
        Iterator it = wordStats.keySet().iterator();
        while (it.hasNext()){
            Object key = it.next();
            System.out.println(key + "\t单词出现了\t" + wordStats.get(key)+"\t次");
        }

    }
    public static String reader(String path) throws IOException {
        File fileRandom =  new File(path);
        FileInputStream isRandom = new FileInputStream(fileRandom);
        byte[]  pipe = new byte[(int) fileRandom.length()];
        isRandom.read(pipe);
        isRandom.close();
        return new String(pipe);
    }
}
